/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>列表为店铺各项消费者保障服务信息以及其当下的状态</li>
          <li>点击“编辑”可以进入店铺加入服务的详情页面，并可以关闭店铺使用的保障服务</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>店铺保障服务列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-input
          class="searchinput"
          v-model="storeName"
          size="small"
          placeholder="店铺名称"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="店铺名称" prop="store_name" width="150"></el-table-column>
        <el-table-column label="保障服务" prop="grt_name" width="150"></el-table-column>
        <el-table-column label="保证金（元）" prop="cost" width="150" :formatter="toFixedPrice"></el-table-column>
        <el-table-column label="状态" prop="auditstate_desc" width="200"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
			<el-button-group>
				<el-button size="small" @click="control(scope.row)" icon="el-icon-s-tools">管理</el-button>
				<el-button size="small" @click="detail(scope.row)" icon="el-icon-zoom-in">查看</el-button>
				<el-button size="small" @click="costLog(scope.row)" icon="el-icon-tickets">保证金日志</el-button>
			</el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>

    <!-- 编辑/查看申请 - dialog -->
    <el-dialog
      title="消费者保障服务管理"
      :visible.sync="dialogVisible"
      width="28%"
      :modal-append-to-body="false"
      center
    >
      <el-form :model="guarantee" label-width="100px">
        <el-form-item label="店铺名称：">{{guarantee.store_name}}</el-form-item>
        <el-form-item label="项目名称：">{{guarantee.grt_name}}</el-form-item>
        <el-form-item label="状态：">{{guarantee.auditstate_desc}}</el-form-item>
        <el-form-item label="关闭状态：">
          <el-radio-group v-model="guarantee.isopen">
            <el-radio :label="1">允许使用</el-radio>
            <el-radio :label="0">禁止使用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="原因备注：" v-if="guarantee.isopen == 0">
          <el-input type="textarea" v-model="logMsg" style="width:350px"></el-input>
          <p class="notic">原因备注应小于200个字符</p>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提 交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getGuaranteeList, updateGuaranteeIsOpen } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      storeName: null,
      guarantee: {},
      dialogVisible: false,
      logMsg: null
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getGuaranteeList({
        store_name: this.storeName,
        page: this.currentPage,
        size: this.pageSize
      }).then(function(res) {
        res.records.forEach(e => {
          if (e.isopen == 0) {
            e.auditstate_desc = "禁止使用";
          } else if (e.joinstate == 0) {
            e.auditstate_desc = "未申请";
          }
        });
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message({
        type: "success",
        message: "刷新成功！"
      });
    },
    control(row) {
      this.guarantee = row;
      this.dialogVisible = true;
    },
    detail(row) {
      this.$router.push({
        name: "guarantee_log_list",
        params: {
          id: row.id,
          currentPage: this.currentPage
        }
      });
    },
    costLog(row) {
      this.$router.push({
        name: "guarantee_costlog_list",
        params: {
          id: row.id,
          currentPage: this.currentPage
        }
      });
    },
    onSubmit() {
      var that = this;
      updateGuaranteeIsOpen(this.logMsg, this.guarantee).then(function(res) {
        if (res.status == 1) {
          that.$message.success({
            message: "操作成功",
            type: "success",
            onClose: function() {
              that.getPage();
              that.dialogVisible = false;
            }
          });
        } else {
          that.$message.error(res.msg);
        }
      });
    },
    toFixedPrice(row) {
      return row.cost.toFixed(2);
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
